package cn.hicard.auth.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.hicard.auth.dao.BaseDao;
import cn.hicard.auth.dao.UserinfoDao;
import cn.hicard.auth.entity.MgUserinfo;
import cn.hicard.core.Page;
import cn.hicard.core.PageResult;
import cn.hicard.core.Where;

/**
 * 用户信息管理DAO接口实现
 * @author zhangy
 *
 */
@Repository
public class UserinfoDaoImpl  extends BaseDao<MgUserinfo> implements UserinfoDao{
	@Override
	public void save(MgUserinfo userinfo)throws Exception{
		super.save(userinfo);
	}
	@Override
	public void update(MgUserinfo userinfo)throws Exception{
		super.update(userinfo);
	}
	@Override
	public void delete(int pkUserinfo)throws Exception{
		super.delete(pkUserinfo);
	}
	@Override
	public MgUserinfo getByPk(int pkUserinfo)throws Exception{
		return super.getByPk(pkUserinfo);
	}
	@Override
	public PageResult<MgUserinfo> search(Where where, Page page) throws Exception {
		PageResult<MgUserinfo> result = new PageResult<MgUserinfo>();
		String listHql = "FROM MgUserinfo WHERE 1=1 ";
		String countHql = "SELECT COUNT(*) FROM MgUserinfo WHERE 1=1 ";		
		listHql += where.queryString();
		countHql += where.queryString();
		// 查数据集合
		result.setDataList(super.findByHqlPage(listHql, page, where.getParams()));
		// 查总共长度
		result.setResultCount(super.findCountByHql(countHql, where.getParams()));
		return result;
	}
	@Override
	public boolean existLoginid(String loginid) throws Exception {
		String hql = "SELECT COUNT(loginid) FROM MgUserinfo WHERE loginid=?";
		return super.findCountByHql(hql, loginid) > 0;
	}
	@Override
	public MgUserinfo getByLoginid(String loginid) throws Exception {
		String hql = "FROM MgUserinfo WHERE loginid=?";
		List<MgUserinfo> list = super.findByHql(hql, loginid);
		if(list == null || list.size() == 0){
			return null;
		}else{
			return list.get(0);
		}
	}
	
}
